/*******************************************************************************
** 文件名称：timer0.h
** 文件作用：TC0操作
** 编写作者：TomFree <付瑞彪>
** 编写时间：2019-12-20
** 文件备注：
**
** 更新记录：
**           2019-12-20 -> 创建文件                                 <Tom Free>
**
**           1 Tab == 4 Spaces     UTF-8     ANSI C Language
*******************************************************************************/
#ifndef __TIMER0_H__
#define __TIMER0_H__

#include "typedef.h"
#include "chip.h"

/* 寄存器重定向 */
#if ((CHIP_TYPE != 48) && (CHIP_TYPE != 88) && (CHIP_TYPE != 168))
#define	TIMSK0	TIMSK
#define	TIFR0	TIFR
#endif  /* END */

#if (CHIP_TYPE != 8)
/* 定时器模式 */
typedef enum
{
	TIMER0_NOMAL    = 0,
	TIMER0_PADJPWM  = 1,
	TIMER0_CTC      = 2,
	TIMER0_FASTPWM  = 3,
		
#if	((CHIP_TYPE == 48) || (CHIP_TYPE == 88) || (CHIP_TYPE == 168))	
	TIMER0_PADJPWM1 = 5,
	TIMER0_FASTPWM1	=7
#endif  /* END */

}TIMER0_MODE;

/* 输出模式 */
typedef enum
{
	TIMER0_NOCONNECT            = 0,
	TIMER0_COMPTURN             = 1,
	TIMER0_COMP0                = 2,
	TIMER0_COMP1                = 3,
	TIMER0_COMP0_TOP1           = 2,
	TIMER0_COMP1_TOP0           = 3,
	TIMER0_UPCOMP0_DOWNCOMP1    = 2,
	TIMER0_UPCOMP1_DOWNCOMP0    = 3
}TIMER0_OUTPUT_MODE;
#endif  /* CHIP_TYPE != 8 */

/* 时钟配置 */
typedef enum
{
	TIMER0_NOCLOCK      = 0,
	TIMER0_DIV1         = 1,
	TIMER0_DIV8         = 2,
#if	((CHIP_TYPE == 64) || (CHIP_TYPE == 128))
	TIMER0_DIV32        = 3,
	TIMER0_DIV64        = 4,
	TIMER0_DIV128       = 5,
	TIMER0_DIV256       = 6,
	TIMER0_DIV1024      = 7
#else
	TIMER0_DIV64        = 3,
	TIMER0_DIV256       = 4,
	TIMER0_DIV1024      = 5,
	TIMER0_T0UP         = 6,
	TIMER0_T0DOWN       = 7
#endif  /* END */
}TIMER0_COLOK;

typedef enum
{
	TIMER0_INTNONE      = 0,
	TIMER0_INTOVF       = 1,
#if ((CHIP_TYPE == 16) || \
     (CHIP_TYPE == 32) || \
     (CHIP_TYPE == 64) || \
     (CHIP_TYPE == 128))
	TIMER0_INTCOMP      = 2,
	TIMER0_INTALL       = 3,
#endif  /* END */
#if ((CHIP_TYPE == 48) || \
     (CHIP_TYPE == 88) || \
     (CHIP_TYPE == 168))
	TIMER0_INTCOMPA     = 2,
	TIMER0_INTCOMPB     = 4,
	TIMER0_INTALL       = 7,
#endif  /* END */
}TIMER0_INTERRUPT;

void TIMER0_Init(
#if (CHIP_TYPE != 8)
				 TIMER0_MODE mode,

#if	((CHIP_TYPE == 48)||(CHIP_TYPE == 88)||(CHIP_TYPE == 168))
				 TIMER0_OUTPUT_MODE omodea,
				 TIMER0_OUTPUT_MODE omodeb,
#else
				 TIMER0_OUTPUT_MODE omode,
#endif
				 
#endif
				 TIMER0_COLOK clock,
				 TIMER0_INTERRUPT inten);

void TIMER0_ColokSet(TIMER0_COLOK clock);

void TIMER0_SetTCNT0(GM_U8 tcnt0);

#if (CHIP_TYPE != 8)

#if	((CHIP_TYPE == 48)||(CHIP_TYPE == 88)||(CHIP_TYPE == 168))
void TIMER0_SetOCR0A(GM_U8 ocr0);
void TIMER0_SetOCR0B(GM_U8 ocr0);
#else
void TIMER0_SetOCR0(GM_U8 ocr0);
#endif

#endif

#endif  /* __TIMER0_H__ */
